import path from 'path'
import { createRouter, createWebHistory, type RouteRecordRaw } from 'vue-router'

const Layout = () => import('@/layout/index.vue')

const pageRoutes: RouteRecordRaw[] = [
  {
    path: '/',
    name: 'Question',
    component: () => import('@/views/question/index.vue'),
    meta: { title: '搜题', icon: 'Search' }
  }
]

export const constantRoutes: RouteRecordRaw[] = [
  {
    path: '/home',
    name: '/home',
    component: Layout,
    children: [
      {
        path: '',
        name: 'Home',
        component: () => import('@/views/HomeView.vue'),
        meta: {
          title: 'HomeTest',
          icon: 'HomeFilled',
          hidden: false
        }
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index.vue'),
    meta: { hidden: true }
  },
  {
    path: '/dashboard',
    name: '/dashboard',
    component: Layout,
    children: [
      {
        path: '',
        component: () => import('@/views/dashboard/index.vue'),
        name: 'Dashboard', // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
        meta: {
          title: '首页',
          icon: 'homepage',
          affix: true,
          keepAlive: true,
          alwaysShow: false
        }
      },
      {
        path: '401',
        component: () => import('@/views/error-page/401.vue'),
        meta: { hidden: true }
      },
      {
        path: '404',
        component: () => import('@/views/error-page/404.vue'),
        meta: { hidden: true }
      }
    ]
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes: [...pageRoutes, ...constantRoutes] as RouteRecordRaw[]
})

export default router
